package com.yan.test.work.testpaging3;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yan.test.work.testpaging3.databinding.LayoutDataItemBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * Create By : 'YWY'
 * On : 2024/4/2
 */
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.VH> {

    private List<DataBean> dataList = new ArrayList<>();

    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new VH(LayoutDataItemBinding.inflate(LayoutInflater.from(parent.getContext()) , parent , false));
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {
        holder.itemView.setData(dataList.get(position));
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    public void setDataList(List<DataBean> dataList) {
        this.dataList.clear();
        this.dataList.addAll(dataList);
        notifyDataSetChanged();
    }

    class VH extends RecyclerView.ViewHolder{
        @NonNull
        public LayoutDataItemBinding itemView;

        public VH(@NonNull LayoutDataItemBinding itemView) {
            super(itemView.getRoot());
            this.itemView = itemView;
        }
    }
}
